package com.kingsoft.dc.khaos.module.spark.model.TechCheck;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static com.kingsoft.dc.khaos.module.spark.constants.TechCheckConst.SpliterType.FixedLength;
import static com.kingsoft.dc.khaos.module.spark.constants.TechCheckConst.SpliterType.FreeLength;

public class NewTechCheckInfo implements Serializable {


  private String filename;   // ddl中的filenme
  private String tablename;  //xml 中的filename
  private String datatype;
  private String spliter; //分隔符
  private Long recordnum;
  private Long filesize;
  private String fileversion;
  private Integer fieldcount;
  private Integer isfixedlength;
  private List<Field> fields = new ArrayList<Field>();
  private List<KeyInfo> keys = new ArrayList<KeyInfo>();
  private String startTimestamp;
  private String endTimestamp;
  private List<String> logList = new ArrayList<>();


  public String getFilename() {
    return filename;
  }

  public void setFilename(String filename) {
    this.filename = filename;
  }

  public String getTablename() {
    return tablename;
  }

  public void setTablename(String tablename) {
    this.tablename = tablename;
  }

  public String getDatatype() {
    return datatype;
  }

  public void setDatatype(String datatype) {
    this.datatype = datatype;
  }

  public Long getRecordnum() {
    return recordnum;
  }

  public void setRecordnum(Long recordnum) {
    this.recordnum = recordnum;
  }

  public Long getFilesize() {
    return filesize;
  }

  public void setFilesize(Long filesize) {
    this.filesize = filesize;
  }

  public String getFileversion() {
    return fileversion;
  }

  public void setFileversion(String fileversion) {
    this.fileversion = fileversion;
  }

  public Integer getFieldcount() {
    return fieldcount;
  }

  public void setFieldcount(Integer fieldcount) {
    this.fieldcount = fieldcount;
  }

  public Integer getIsfixedlength() {
    return isfixedlength;
  }
//  如果是定长，则标识为1，否则标识为0。
  public void setIsfixedlength(Integer isfixedlength) {
    this.isfixedlength = isfixedlength;
    if(isfixedlength == FixedLength.code) {
        this.spliter = FixedLength.spliter;
    }else if(isfixedlength == FreeLength.code) {
      this.spliter = FreeLength.spliter;
    }else{
      throw new RuntimeException("isfixedlength=="+isfixedlength +" ,数据不符合格式(0,1),请检查ddl文件");
    }
  }
  public List<Field> getFields() {
    return fields;
  }

  public void setFields(List<Field> fields) {
    this.fields = fields;
  }

  public List<KeyInfo> getKeys() {
    return keys;
  }

  public void setKeys(List<KeyInfo> keys) {
    this.keys = keys;
  }

  public String getStartTimestamp() {
    return startTimestamp;
  }

  public void setStartTimestamp(String startTimestamp) {
    this.startTimestamp = startTimestamp;
  }

  public String getEndTimestamp() {
    return endTimestamp;
  }

  public void setEndTimestamp(String endTimestamp) {
    this.endTimestamp = endTimestamp;
  }
  public void addField(String fieldname,String fieldtype){
    this.getFields().add(new Field(fieldname,fieldtype,this.getIsfixedlength()));
  }
  public void addKey(String fieldname){
    for(int i = 0 ;i< fields.size();i++) {
      if (fields.get(i).fieldname.equals(fieldname)){
        this.getKeys().add(new KeyInfo(fieldname, i));
        break;
      }else if(i == fields.size()-1){
        throw new KsyunTechCheckException("主键("+ fieldname +")在字段列表中不存在");
      }
    }
  }
  public String getSpliter() {
    return spliter;
  }
  public void setSpliter(String spliter) {
    this.spliter =spliter ;
  }
  public List<String> getLogList(){
    return logList;
  }
  public void addLog(String log){
    this.logList.add(log);
  }


}
